﻿@using Smartstore.Web.Models.Search

@model SearchResultModel

@{
    var hitGroups = Model.HitGroups.Where(x => x.Hits.Any()).OrderBy(x => x.Ordinal).ToArray();
    var hasContent = Model.TopProducts.Items.Count > 0 || hitGroups.Any();
    var isMultiCol = false;
    if (hasContent)
    {
        isMultiCol =
            Model.TopProducts.Items.Count > 0
            && (hitGroups.Length > 1 && hitGroups.Sum(x => x.Hits.Count) > 4);
    }
}

@if (!hasContent)
{
    return;
}

@if (isMultiCol)
{
    <div class="row no-gutters instasearch-row">
        <div class="col col-sm-6 col-xl-5 instasearch-col">
            @foreach (var group in hitGroups)
            {
                <partial name="InstantSearch.HitGroup" model="group" />
            }
        </div>
        <div class="col col-sm-6 col-xl-7 instasearch-col">
            <h6 class="instasearch-group-header">@T("Search.Hits")</h6>
            <partial name="InstantSearch.TopProducts" model="Model" />
        </div>
    </div>
}
else
{
    foreach (var group in hitGroups)
    {
        <partial name="InstantSearch.HitGroup" model="group" />
    }

    if (Model.TopProducts.Items.Count > 0)
    {
        <h6 class="instasearch-group-header">@T("Search.Hits")</h6>

        <partial name="InstantSearch.TopProducts" model="Model" />
    }
}
